package com.cbwl.eoas.cms.service.impl.sysconfig;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cbwl.eoas.cms.api.sysconfig.ISysRoleResourceService;
import com.cbwl.eoas.cms.dao.sysconfig.ISysRoleResourceDao;
import com.cbwl.eoas.cms.model.sysconfig.SysRoleResourceDTO;
import com.cbwl.eoas.common.base.BaseServiceImpl;


/**
 * 
 * <p>[描述信息：SysRoleResourceDAO接口]</p>
 *
 * @author 虞云波 - yuyunbo@3856.cc
 * @version 1.0 Created on 2017年10月12日 下午13:29:23
 */
@Service
public class SysRoleResourceServiceImpl  extends BaseServiceImpl<SysRoleResourceDTO>  implements ISysRoleResourceService  {

	@Autowired
	private ISysRoleResourceDao sysRoleResourceDao;
	
	
	@Override
	public long saveOrUpdateSysRoleResource(SysRoleResourceDTO bean) throws Exception {
		
		String idStr = bean.getIdStr();
		
		//先删除当前角色拥有的资源
		sysRoleResourceDao.deleteRoleResourceByRid(bean);
		
		if(idStr.length()>0){
			String[] array = idStr.split(",");
			SysRoleResourceDTO rrBean = new SysRoleResourceDTO();
			for(String id:array){
				rrBean.setRid(bean.getRid());
				rrBean.setResid(Long.valueOf(id));
				
				sysRoleResourceDao.saveObject(rrBean);
			}
		}
		
		return idStr.length();
	}
	
	
	
}
